home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Communications / pcomm / Source / s_prompt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  3.0 KB  |  143 lines

  1. /*
  2.  * Prompting routines used in the setup menus.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <curses.h>
  7. #include "config.h"
  8. #include "misc.h"
  9.  
  10. /*
  11.  * Prompt for a string at line 21 (with optional line 22 for additional
  12.  * information).  Display the new string in bold at its original location
  13.  * in the menu.  Used in virtually all of the *_setup() routines.  Since
  14.  * it uses get_str(), the return value points to a static area.
  15.  */
  16.  
  17. char *
  18. str_prompt(win, y, x, p1, p2)
  19. WINDOW *win;
  20. int y, x;
  21. char *p1, *p2;
  22. {
  23.     extern char *null_ptr;
  24.     char *ans, *get_str();
  25.                     /* print first prompt last */
  26.     mvwaddstr(win, 22, 0, p2);
  27.     mvwaddstr(win, 21, 0, p1);
  28.     waddstr(win, ": ");
  29.     wrefresh(win);
  30.  
  31.     if ((ans = get_str(win, 80, "", "\n")) == NULL)
  32.         return(NULL);
  33.                     /* check the value */
  34.     if (!strcmp(ans, " "))
  35.         ans = null_ptr;
  36.                     /* display the value in bold */
  37.     clear_line(win, y, x, FALSE);
  38.     wattrstr(win, A_BOLD, ans);
  39.  
  40.     return(ans);
  41. }
  42.  
  43. /*
  44.  * Same as above, except we return a single character.
  45.  */
  46.  
  47. char
  48. chr_prompt(win, y, x, p1, p2)
  49. WINDOW *win;
  50. int y, x;
  51. char *p1, *p2;
  52. {
  53.     char *ans, *get_str();
  54.                     /* print first prompt last */
  55.     mvwaddstr(win, 22, 0, p2);
  56.     mvwaddstr(win, 21, 0, p1);
  57.     waddstr(win, ": ");
  58.     wrefresh(win);
  59.  
  60.     if ((ans = get_str(win, 1, "", "\n")) == NULL)
  61.         return('\0');
  62.                     /* display the value in bold */
  63.     mvwaddstr(win, y, x, "  ");
  64.     wrefresh(win);
  65.     mvwattrstr(win, y, x, A_BOLD, ans);
  66.  
  67.     return(*ans);
  68. }
  69.  
  70. /*
  71.  * Same as above, except that it prompts for a three digit number.
  72.  */
  73.  
  74. int
  75. num_prompt(win, y, x, p1, p2)
  76. WINDOW *win;
  77. int y, x;
  78. char *p1, *p2;
  79. {
  80.     int i;
  81.                     /* print first prompt last */
  82.     mvwaddstr(win, 22, 0, p2);
  83.     mvwaddstr(win, 21, 0, p1);
  84.     waddstr(win, ": ");
  85.     wrefresh(win);
  86.  
  87.     if ((i = get_num(win, 3)) == -1)
  88.         return(-1);
  89.                     /* display the value in bold */
  90.     mvwaddstr(win, y, x, "    ");
  91.     wrefresh(win);
  92.     mvwattrnum(win, y, x, A_BOLD, i);
  93.                     /* return the number */
  94.     return(i);
  95. }
  96.  
  97. /*
  98.  * Prompts for a selection from a menu.  We display the prompt lines,
  99.  * and show the choices one at a time.  The user selects the currently
  100.  * showing choice by hitting a carriage return.  Unlike the similar
  101.  * routines in d_prompt(), the first choice shown is not necessarily
  102.  * the current.
  103.  */
  104.  
  105. char *v_yes[3] = {"YES", "NO", NULL};
  106. char *v_yn[3] = {"Y", "N", NULL};
  107.  
  108. char *
  109. menu_prompt(win, y, x, p, menu)
  110. WINDOW *win;
  111. int y, x;
  112. char *p, *menu[];
  113. {
  114.     char ans;
  115.     int i, cy, cx;
  116.                     /* print first prompt last */
  117.     mvwaddstr(win, 22, 0, "Press any key to change, or <CR> to accept");
  118.     mvwaddstr(win, 21, 0, p);
  119.     waddstr(win, ": ");
  120.                     /* show first choice */
  121.     i = 0;
  122.     getyx(win, cy, cx);
  123.     mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  124.     wmove(win, cy, cx);
  125.     wrefresh(win);
  126.                     /* show the choices one at a time */
  127.     while ((ans = wgetch(win)) != '\r') {
  128.         i++;
  129.         if (menu[i] == NULL)
  130.             i = 0;
  131.         if (ans == ESC)
  132.             return(NULL);
  133.         mvwprintw(win, cy, cx, "%-30.30s", menu[i]);
  134.         wmove(win, cy, cx);
  135.         wrefresh(win);
  136.     }
  137.                     /* display the value in bold */
  138.     clear_line(win, y, x, FALSE);
  139.     wattrstr(win, A_BOLD, menu[i]);
  140.                     /* return the value */
  141.     return(menu[i]);
  142. }
  143.